--[[
    Lua 5.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
]]

-- lua实现oop原理2

function newUser(username, password, age)
    local u = {}
    u.username = username
    u.password = password
    u.age = age
    
    function u:getUsername()
        return u.username
    end

    function u:setUsername(username)
        u.username = username
    end

    return u
end

u1 = newUser("Jack", "pswd1", 35)
u2 = newUser("Lily", "pswd2", 26)
print(u1)
print(u2)
print(u1:getUsername(), u1.password, u1.age)
print(u2:getUsername(), u2.password, u2.age)
